package com.example.goodpet.activity.Fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.ViewPager2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.goodpet.R;
import com.example.goodpet.activity.adapter.SearchResultPagerAdapter;
import com.example.goodpet.base.BaseFragment;
import com.example.goodpet.home.adapter.HomePagerAdapter;
import com.example.goodpet.home.fragment.HomeFragment;
import com.example.goodpet.home.homeFocus.fragment.HomeFocusFragment;
import com.example.goodpet.home.homeRecommend.fragment.HomeRecommendFragment;
import com.example.goodpet.utils.UIUtils;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

public class SearchResultFragment extends BaseFragment {


    private SearchResultPagerAdapter adapter;

    private ViewPager2 vp_search_result;

    private TabLayout tabLayout;
    private TabLayoutMediator mediator;

    private String searchContent;


    private int PET=1;
    private int COMMUNITY=2;
    private int USER=3;

    @Override
    public View initView() {
        View view = View.inflate(mContext, R.layout.fragment_search_result, null);
        vp_search_result=view.findViewById(R.id.vp_search_result);
        tabLayout=view.findViewById(R.id.tabLayout);
        return view;
    }

    @Override
    public void initData() {
        searchContent = getArguments().getString("searchContent");
        //初始化Home适配器，添加fragment进适配器
        initAdapter();
    }


    /**
     * 初始化Home适配器，添加fragment进适配器
     */
    private void initAdapter() {
        adapter = new SearchResultPagerAdapter(this);
        adapter.addFragment(new SearchResultOfPetFragment(),searchContent);
        adapter.addFragment(new SearchResultOfCommunityFragment(),searchContent);
        adapter.addFragment(new SearchResultOfUserFragment(),searchContent);
        vp_search_result.setAdapter(adapter);
        int type = getArguments().getInt("type");

        if(type==PET){
            vp_search_result.setCurrentItem(0);
        }else if(type==COMMUNITY){
            vp_search_result.setCurrentItem(1);
        }else if(type==USER){
            vp_search_result.setCurrentItem(2);
        }
        mediator=new TabLayoutMediator(tabLayout, vp_search_result, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(UIUtils.getStringArr(R.array.search_result_info_tab)[position]);
            }
        });
        mediator.attach();

    }

}